

import buildings.Building;
import buildings.Space;
import buildings.Floor;
import buildings.exceptions.InexchangeableFloorsException;
import buildings.exceptions.InexchangeableSpacesException;
import buildings.office.OfficeBuilding;
import buildings.office.OfficeFloor;
import buildings.office.Office;
import buildings.dwelling.Dwelling;
import buildings.dwelling.Flat;
import buildings.dwelling.DwellingFloor;
import buildings.*;
import buildings.dwelling.DwellingFactory;
import buildings.dwelling.hotel.*;
import buildings.office.OfficeFactory;
import buildings.threads.*;
import java.io.*;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * 
 * @author Evgeny Obednin
 */
public class TestClass {

    public static void main(String[] args) {
            //        Dwelling dw = new Dwelling(new DwellingFloor[]{
            //                    new DwellingFloor(1),
            //                    new DwellingFloor(new Flat[]{
            //                        new Flat(65), new Flat(70, 3)
            //                    }),
            //                    new DwellingFloor(new Flat[]{
            //                        new Flat(65), new Flat(32), new Flat(99)
            //                    })
            //                });
            //
            //        System.out.println("Dwelling before any operation: ");
            //        for (int i = 0; i < dw.getFloorCount(); i++) {
            //            System.out.println("Floor #" + i);
            //            for (int j = 0; j < dw.getFloorByNumber(i).getFlatCount(); j++) {
            //                Flat f = dw.getFloorByNumber(i).getFlatByNumber(j);
            //                System.out.println(f.getFlatSquare() + " " + f.getRoomCount());
            //            }
            //        }
            //        System.out.println("Total: " + dw.getTotalFlatCount() + " flats, "
            //                + dw.getTotalFlatSquare() + " " + dw.getTotalRoomCount());
            //
            //        dw.addFlatByNumber(0, new Flat(10, 1));
            //        dw.setFlatByNumber(1, new Flat(68, 3));
            //        dw.deleteFlatByNumber(2);
            //
            //        System.out.println("Dwelling after all operations: ");
            //        for (int i = 0; i < dw.getFloorCount(); i++) {
            //            System.out.println("Floor #" + i);
            //            for (int j = 0; j < dw.getFloorByNumber(i).getFlatCount(); j++) {
            //                Flat f = dw.getFloorByNumber(i).getFlatByNumber(j);
            //                System.out.println(f.getFlatSquare() + " " + f.getRoomCount());
            //            }
            //        }
            //        System.out.println("Total: " + dw.getTotalFlatCount() + " flats, "
            //                + dw.getTotalFlatSquare() + " " + dw.getTotalRoomCount());
            //
            //        Flat[] flats = dw.sortFlatsBySquare();
            //
            //        System.out.println("---SORTING---");
            //        for (int i = 0; i < flats.length; i++) {
            //            System.out.println(flats[i].getFlatSquare() + " "
            //                    + flats[i].getRoomCount());
            //        }
            //        
            //        Office[] m = {new Office(1,1),new Office(2,2)};
            //        OfficeFloor f = new OfficeFloor(m);
            //        Space o = f.getSpaceByNumber(10);
            //        Office o2 = new Office(100, 2);
            //        f.addSpaceByNumber(1, o2);
            //        Space[] x = f.getSpaces();
            //        f.setSpaceByNumber(3, x[2]);
            //        f.deleteSpaceByNumber(0);
            //        x = f.getSpaces();
            //        Space bestSquare = f.getBestSpace();
            //        OfficeBuilding b = new OfficeBuilding(4, new int[]{1,2,3,4});
            //        Space[] sortedOffices = b.getSortedSpaces();
            //        b.addSpaceByNumber(3, o2);
            //        
            //        OfficeFloor floor = new OfficeFloor(3);
            //        float bestSpace = floor.getBestSpace().getSquare();
            //        floor.getSpaceByNumber(4);
            //        DwellingFloor floor2 = new DwellingFloor(3);
            //        floor2.getSpaceByNumber(-2);
            //----------------------------------------------------------------------------------------        
            //        Floor floor1 = new DwellingFloor(new Space[]{new Flat(1, 1), new Flat(11, 11)});
            //        Floor floor2 = new OfficeFloor(new Space[]{new Office(2, 2), new Office(1, 1)}); 
            //        Building b = new Dwelling(new Floor[]{floor1, floor2});
            //        
            //        try {
            //            PlacementExchanger.exchangeFloorRooms(floor1, 0, floor2, 1);
            //        }
            //        catch (InexchangeableSpacesException e) {
            //            System.out.println("Невозможно обменяться помещениями!");
            //        }
            //        
            //        Building b1 = new Dwelling(new Floor[]{floor1});
            //        Building b2 = new OfficeBuilding(new Floor[]{floor2});
            //        try {
            //            PlacementExchanger.exchangeBuildingFloors(b1, 0, b2, 0);
            //        } catch(InexchangeableFloorsException e) {
            //            System.out.println("Невозможно обменяться этажами!");
            //        }
            //        
            //        try {
            //            Buildings.writeBuilding(b, new FileWriter("out.txt"));
            //            b = Buildings.readBuilding(new FileReader("out.txt"));
            //            Buildings.outputBuilding(b, new FileOutputStream("out.bin"));
            //            b2 = Buildings.inputBuilding(new FileInputStream("out.bin"));
            //            Buildings.SerializationWrite(b);
            //            b1 = Buildings.SerializationRead();
            //        } 
            //        catch(IOException | ClassNotFoundException e) {
            //            System.out.println("Что-то пошло не так...");
            //        }
            //        
            //        Floor hFloor1 = new DwellingFloor(new Space[]{new Flat(1, 1), new Flat(11, 11)});
            //        Floor hFloor2 = new OfficeFloor(new Space[]{new Office(2, 2), new Office(22, 22)});
            //        Floor hFloor3 = new HotelFloor(new Space[]{new Flat(3, 3), new Flat(33, 33)});
            //        Floor hFloor4 = new HotelFloor(new Space[]{new Flat(3, 3), new Flat(32, 32)});
            //        ((HotelFloor)hFloor4).setStars(3);
            //        
            //        Hotel hotel = new Hotel(new Floor[]{hFloor1, hFloor2, hFloor3, hFloor4});
            //        int t = hotel.getStars();
            //        Space bestSpace = hotel.getBestSpace();
            //        
            //        Iterator iter = hotel.iterator();
            //        Floor floor;
            //        for(int i = 0; i < hotel.getFloorCount(); i++) {
            //            floor = (Floor)iter.next();
            //        }
            //        
            //        Hotel jjj = new Hotel(2, new int[]{2,3});
            //        
            //        Buildings.setBuildingFactory(new OfficeFactory());
            //        Building building = Buildings.createBuilding(
            //                new Floor[]{hFloor1, hFloor2, hFloor3, hFloor4});
            //        int r = 0;
            //        
            //-----------------------------------------------------------------------------------------        
            //        Floor hFloor1 = new DwellingFloor(new Space[]{new Flat(1, 1), new Flat(11, 11)});
            //        Floor hFloor2 = new OfficeFloor(new Space[]{new Office(2, 2), new Office(22, 22)});
            //        Floor hFloor3 = new HotelFloor(new Space[]{new Flat(3, 3), new Flat(33, 33)});
            //        Floor hFloor4 = new HotelFloor(new Space[]{new Flat(3, 3), new Flat(32, 32)});
            //        ((HotelFloor)hFloor4).setStars(3);
            //        Buildings.setBuildingFactory(new HotelFactory());
            //        Building building = Buildings.createBuilding(
            //                new Floor[]{hFloor1, hFloor2, hFloor3, hFloor4});
            //        building.getFloorCount();
            //        System.out.println(building.getSpaceByNumber(1));
            //        System.out.println(building.getFloorByNumber(2));
            //        System.out.println(building);
            //        
            //        Buildings.setBuildingFactory(new HotelFactory());
            //        Building b1 = Buildings.createBuilding(
            //                new Floor[]{hFloor1, hFloor2, hFloor3, hFloor4});
            //        Building b2 = Buildings.createBuilding(
            //                new Floor[]{hFloor1, hFloor2, hFloor3, hFloor4});
            //        
            //        //System.out.println(b1.equals(b2));
            //        
            //        
            //        Flat f = new Flat(1, 13);
            //        Space sp = new Flat(1, 13);
            //        System.out.println(f.equals(null));
            //        System.out.println(f.equals(sp));
            //        f.hashCode();
            //        
            //        Floor hFloor5 = new HotelFloor(new Space[]{new Flat(3, 4), new Flat(33, 33)});
            //        
            //        int hb1 = hFloor3.hashCode();
            //        int hb2 = hFloor5.hashCode();
            //            
            //        
            //        Building b = null;
            //        try {
            //            b = (Building)b1.clone();
            //        } catch (CloneNotSupportedException e) {
            //            
            //        }
            //        System.out.println(b1);
            //        System.out.println(b);
                    
            //        Floor f = new DwellingFloor(500);
                    
            //        Cleaner c = new Cleaner(f);
            //        Repairer r2 = new Repairer(f);
            //        r2.start();
            //        c.start();
                    
            //        Semaphore s = new Semaphore(f);
            //        Runnable r = new SequentalCleaner(s);
            //        Thread cleaner = new Thread(r);
            //        r = new SequentalRepairer(s);
            //        Thread repairer = new Thread(r);
            //        
            //        cleaner.start();
            //        repairer.start();
        
        
        
        Space space = null;
        Floor floor = null;
        Building building = null;
        try {                    
            space = Buildings.createSpace((float)666.666, 
                    Class.forName("buildings.dwelling.Flat"));
            floor = Buildings.createFloor(new Space[]{space}, 
                    Class.forName("buildings.dwelling.DwellingFloor"));
            building = Buildings.createBuilding(new Floor[] {floor}, 
                    Class.forName("buildings.dwelling.hotel.Hotel"));
            
            building = Buildings.readBuilding(new FileReader("C://input.txt"), 
                Class.forName("buildings.dwelling.hotel.Hotel"), 
                Class.forName("buildings.dwelling.DwellingFloor"), 
                Class.forName("buildings.dwelling.Flat"));
        } catch (ClassNotFoundException | IOException ex) {
            Logger.getLogger(TestClass.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }
}
